package 刷题7月.回文数0717;

import java.util.ArrayList;
import java.util.List;

class Solution {
    public boolean isPalindrome(int x) {
        if(x < 0) return false;
        String s = String.valueOf(x);
        char[] chars = s.toCharArray();
        for(int i = 0;i < chars.length;i++){
            if(chars[i] != chars[chars.length-1-i]){
                return false;
            }
        }
        return true;
    }
}

class Solution1 {
    /**
     * @param n: non-negative integer n.
     * @return: return whether a binary representation of a non-negative integer n is a palindrome.
     */
    public boolean isPalindrome(int n) {
        // Write your code here
        int k;
        List<Integer> B=new ArrayList<Integer>();
        while(n>=1){
            k=n%2;
            B.add(k);
            n=n/2;
        }
        int j=0;
        int c=B.size();
        for(j=0;j<c;j++){
            if(B.get(j)!=B.get(c-j-1)){
                return false;
            }
        }
        return true;
    }
}